package cn.edu.scau.dao;

import cn.edu.scau.entity.Manager;
import org.apache.ibatis.jdbc.SQL;

public class ManagerSqlProvider {

    public String insertSelective(Manager record) {
        SQL sql = new SQL();
        sql.INSERT_INTO("manager");
        
        if (record.getUserId() != null) {
            sql.VALUES("userId", "#{userId,jdbcType=INTEGER}");
        }
        
        if (record.getUserAccount() != null) {
            sql.VALUES("userAccount", "#{userAccount,jdbcType=VARCHAR}");
        }
        
        if (record.getUserTelephone() != null) {
            sql.VALUES("userTelephone", "#{userTelephone,jdbcType=VARCHAR}");
        }
        
        if (record.getUserPassword() != null) {
            sql.VALUES("userPassword", "#{userPassword,jdbcType=VARCHAR}");
        }
        
        if (record.getUserPosition() != null) {
            sql.VALUES("userPosition", "#{userPosition,jdbcType=INTEGER}");
        }
        
        if (record.getUserUseflag() != null) {
            sql.VALUES("userUseflag", "#{userUseflag,jdbcType=BIT}");
        }
        
        return sql.toString();
    }

    public String updateByPrimaryKeySelective(Manager record) {
        SQL sql = new SQL();
        sql.UPDATE("manager");
        
        if (record.getUserAccount() != null) {
            sql.SET("userAccount = #{userAccount,jdbcType=VARCHAR}");
        }
        
        if (record.getUserTelephone() != null) {
            sql.SET("userTelephone = #{userTelephone,jdbcType=VARCHAR}");
        }
        
        if (record.getUserPassword() != null) {
            sql.SET("userPassword = #{userPassword,jdbcType=VARCHAR}");
        }
        
        if (record.getUserPosition() != null) {
            sql.SET("userPosition = #{userPosition,jdbcType=INTEGER}");
        }
        
        if (record.getUserUseflag() != null) {
            sql.SET("userUseflag = #{userUseflag,jdbcType=BIT}");
        }
        
        sql.WHERE("userId = #{userId,jdbcType=INTEGER}");
        
        return sql.toString();
    }
    public String updateByUserAccountSelective(Manager record) {
        SQL sql = new SQL();
        sql.UPDATE("manager");

        if (record.getUserTelephone() != null) {
            sql.SET("userTelephone = #{userTelephone,jdbcType=VARCHAR}");
        }

        if (record.getUserPassword() != null) {
            sql.SET("userPassword = #{userPassword,jdbcType=VARCHAR}");
        }

        if (record.getUserPosition() != null) {
            sql.SET("userPosition = #{userPosition,jdbcType=INTEGER}");
        }

        if (record.getUserUseflag() != null) {
            sql.SET("userUseflag = #{userUseflag,jdbcType=BIT}");
        }

        sql.WHERE("userAccount = #{userAccount,jdbcType=INTEGER}");

        return sql.toString();
    }
    public String findById(Integer userId){
        SQL sql = new SQL();
        sql.SELECT("userId, userAccount, userTelephone, userPassword, userPosition, userUseflag");
        sql.FROM("manager");
        if(userId!=null){
            sql.WHERE(" userId like concat('%',#{userId},'%')");
        }
        sql.WHERE(" userUseflag = true");
        return sql.toString();
    }
}